#include <vector>
#include <math.h>
#include <time.h>

#include "base/ccMacros.h"
#include "base/CCVector.h"
#include "base/CCValue.h"

using namespace std;
using namespace cocos2d;


class Block
{
public:

	Block(int __isPath)
	{
		isPath = __isPath == 0 ? true : false;
	}

	float size;

	float G;
	float H;

	bool isPath;

	Block* parent;

	float getF()
	{
		return G + H;
	}

	int indexX;
	int indexY;
};

#ifndef __ASTAR_MANAGER_H__
#define __ASTAR_MANAGER_H__
class AStarManager
{
public:
	AStarManager(){	};
	~AStarManager(){};

	static AStarManager* getInstance()
	{
		static AStarManager* _AStarManager = NULL;
		if (_AStarManager == NULL)
		{
			_AStarManager = new AStarManager();
		}
		return _AStarManager;

	}

	Vector< Vector< Value* >* >* searchPath(vector< vector< int > > &mapData, int startX, int startY, int endX, int endY);

private:
	float getTwoGLen(int indexX1, int indexY1, int indexX2, int indexY2)
	{
		int numX = abs(indexX1 - indexX2);
		int numY = abs(indexY1 - indexY2);
		int diff = abs(numX - numY);
		int tempMin = numX > numY ? numY : numX;
		return (pow(2, 2)*tempMin + diff);
	}

	bool checkIsInList(vector<Block*>& list, Block* block)
	{
		for (vector<Block*>::iterator it = list.begin(); it != list.end(); it++)
		{
			if (*it == block)
			{
				return true;
			}
		}
		return false;
	}

private:
	const int DIRS = 8;
	const int searchDirs[][2] = {
			{0, 1},
			{ 1, 1 },
			{ 1, 0 },
			{ 1, -1 },
			{ 0, -1 },
			{ -1, -1 },
			{ -1, 0 },
			{ -1, 1 },
	};

};
#endif